﻿<?php
session_start();

if(isset($_POST['ok']))
{
	if($_POST['txtCaptcha'] == NULL)
	{
		echo "Please enter your code";
	}
	else
	{
		if($_POST['txtCaptcha'] == $_SESSION['security_code'])
		{
			echo $_SESSION['security_code'];
		}
		else
		{
			echo "Ma lenh khong hop le";
		}
	}
}

?>
<html>
<head>
<script>
	function check_captcha()
	{
		
		var codes	= 
		<?php 
			echo '"';
			echo $_SESSION['security_code'];
			echo '"';
		?>
		//alert(sessionStorage.aaa);
		var ten=document.getElementById("nhapvao").value;
		if(ten == code)
			document.getElementById("test").innerHTML = "Hợp lệ .";
		else document.getElementById("test").innerHTML = "Không hợp lệ .";
	}
	
	
</script>
</head>
<body>
<form action="form.php" method=post>
<table> 
  <tr>
    <td align="left">
      <label for="captcha">Captcha</label>
    </td>
    <td>
      <input onchange="check_captcha()" id="nhapvao" type="text" name="txtCaptcha" maxlength="10" size="32" tabindex="1"/>
    </td>
    <td> 
      <img src="random_image.php" /><span id="test"> </span>
    </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>
      <input type=submit name=ok value="Check" tabindex="2"/>
    </td>
  </tr>
</table> 
</form>
</body>
</html>